import {
  getOptionalField,
  getTableData,
} from '@/api/dualStack/comprehensiveQuery';

export const comprehensiveQueryModule = {
  state: {
    tableData: [],
    tableDataCount: 0,
  },
  mutations: {
    setTableData(state, { statusCode, data }) {
      if (statusCode === 200) {
        const { records, count } = data;

        state.tableData.splice(0, state.tableData, ...records);
        state.tableDataCount = count;
      }
    },
  },
  actions: {
    // 获取可用字段
    getOptionalField_action({ commit }) {
      return new Promise((resolve, reject) => {
        getOptionalField()
          .then(response => {
            resolve(response.data);
          })
          .catch(error => {
            reject(error);
          });
      });
    },

    getTableData_action({ commit }, resData) {
      return new Promise((resolve, reject) => {
        getTableData(resData)
          .then(response => {
            // commit('setTableData', response.data);
            resolve(response.data);
          })
          .catch(error => {
            reject(error);
          });
      });
    },
  },
};
